<?php
/**
 * Created by PhpStorm.
 * User: leo
 * Date: 2018/10/13
 * Time: 11:40
 */

namespace app\admin\controller;


use think\facade\Request;
use app\common\model\Config as ConfigModel;

class Config extends Common
{
    /**
     * 配置列表
     * @return \think\response\Json|\think\response\View
     * @throws \think\exception\DbException
     */
    public function index() {
        if (Request::isAjax()) {
            $data = (ConfigModel::getList())->toArray();
            return return_data('配置列表', 0, $data['data'], $data['total']);
        }
        return view();
    }

    /**
     * 创建或者编辑配置
     * @return \think\response\Json|\think\response\View
     */
    public function save_config() {
        $id = input('param.id', 0);
        if (request()->isAjax()) {

            $param['key'] = input('param.key', '');
            $param['value'] = input('param.value', '');
            $data = ConfigModel::createOrUpdateConfig($param, $id);
            return $data;
        } else {
            return view();
        }
    }
}